#include "stm32f4xx.h"
#include <rtthread.h>
#include "finsh.h"
#include "arm_math.h"

void RNG_Configuration(void)
{
	RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG,ENABLE);
	RNG_Cmd(ENABLE);
}

arm_matrix_instance_f32 m1,m2,m3;
void matrix(int cmd)
{
	u16 i;
	rt_tick_t tick;
		
	switch(cmd)
	{
	case 1:		
		#define ROWS 50
		#define COLS 20	
		m1.pData=rt_malloc(ROWS*COLS*sizeof(float32_t));
		m2.pData=rt_malloc(ROWS*COLS*sizeof(float32_t));
		m3.pData=rt_malloc(ROWS*COLS*sizeof(float32_t));
		while(RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET);
		srand(RNG_GetRandomNumber());
		for(i=0;i<ROWS*COLS;i++)
		{
			m1.pData[i]=rand();
			m2.pData[i]=rand();		
		}		 
		m1.numRows=ROWS;
		m1.numCols=COLS;
		m2.numRows=ROWS;
		m2.numCols=COLS;
		m3.numRows=ROWS;
		m3.numCols=COLS;
		tick=rt_tick_get();	
		for(i=0;i<50000;i++)
			arm_mat_add_f32(&m1,&m2,&m3);  
		tick=rt_tick_get()-tick;	 
		rt_kprintf("Use tick:%d\n",tick);	
		rt_free((void *)m1.pData);
		rt_free((void *)m2.pData);
		rt_free((void *)m3.pData);	 
		break;
	default :
		rt_kprintf("Wrong Param!\n");	 
		break;
	}
}												 
FINSH_FUNCTION_EXPORT(matrix, matrix calculate)
